import {defineConfig} from "vite";
import vue from "@vitejs/plugin-vue";
import wasm from "vite-plugin-wasm";
import topLevelAwait from "vite-plugin-top-level-await";
import path from "path"
import {createSvgIconsPlugin} from 'vite-plugin-svg-icons'

const {name} = require('./package');
import mkcert from "vite-plugin-mkcert";


export default defineConfig({
  //注意：打包时base需设置为插件编号
  //base: '',
  plugins: [
    vue(),
    mkcert(),
    /*qiankun('my-app', {
      useDevMode: true
    }),*/
    wasm(),
    topLevelAwait(),
    createSvgIconsPlugin({
      // Specify the icon folder to be cached
      iconDirs: [path.resolve(process.cwd(), 'src/icons')],
      // Specify symbolId format
      symbolId: 'icon-[dir]-[name]',
    }),
  ],
  server: {
    port: 8083,
    https: true,
    strictPort: true,
    headers: {
      'Access-Control-Allow-Origin': '*',
    },
    proxy: {
      "/api": {
        target: "http://localhost:8086",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ""),
      },
    },
  },
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "src"),
    },
  },
  output: {
    // 把子应用打包成 umd 库格式
    library: `${name}-[name]`,
    libraryTarget: 'umd',
    jsonpFunction: `webpackJsonp_${name}`,
  },
})